import { INDEX, toBondDetail } from '@/utils';
import type { IColumnsOption } from 'vc';

export function useTable() {
  const columns = reactive<IColumnsOption[]>([
    { ...INDEX },
    {
      title: '债券简称',
      field: 'bondShortName',
      width: 160,
      fixed: 'left',
      slots: {
        default({ row }) {
          return row.id ? <a onClick={() => toBondDetail(row.id)} v-html={row.bondShortName}></a> : '-';
        }
      }
    },
    {
      title: '债券代码',
      field: 'securitiesCode',
      width: 110,
      align: 'center'
    },
    {
      title: '绿债口径/品种',
      field: 'labels',
      width: 180,
      slots: {
        default({ row }) {
          return row?.labels?.length
            ? row.labels.map((item) => {
                const { color, bgColor, name } = item;
                return <span class="mr-2" style={{ color: color, background: bgColor, padding: '2px 5px', fontSize: '11px' }} v-html={name}></span>;
              })
            : '-';
        }
      }
    },
    {
      title: '绿债分类',
      width: 200,
      field: 'greenProjectClassifications',
      align: 'left',
      formatter({ cellValue }) {
        return cellValue?.length ? cellValue?.join('、') : '-';
      }
    },
    {
      title: '债券类型',
      width: 120,
      field: 'bondTypeName',
      align: 'center'
    },
    {
      title: '债券期限',
      field: 'bondPeriod',
      width: 110,
      align: 'center'
    },
    {
      title: '发行规模',
      field: 'issuingScale',
      width: 110,
      align: 'center',
      slots: {
        default({ row }) {
          return row.issuingScale ? <span v-html={row.issuingScale + '亿'}></span> : '-';
        }
      }
    },
    {
      title: '发行起始日',
      width: 110,
      field: 'issuingDate',
      align: 'center'
    },
    {
      title: '票面利率',
      width: 110,
      field: 'couponRateDisplay',
      align: 'center',
      slots: {
        default({ row }) {
          return row.couponRateDisplay ? <span v-html={row.couponRateDisplay + '%'}></span> : '-';
        }
      }
    },
    {
      title: '计息方式',
      width: 110,
      field: 'calculateInterestMethod',
      align: 'center'
    },
    {
      title: '起息日',
      width: 110,
      field: 'valueDate',
      align: 'center'
    },
    {
      title: '到期日',
      width: 110,
      field: 'maturityDate',
      align: 'center'
    },
    {
      title: '债券评级',
      width: 110,
      field: 'facilityRating',
      align: 'center'
    }
  ]);

  return {
    columns
  };
}
